import React, { Component }  from 'react';
import Taro from '@tarojs/taro';
import { View, Text , Button} from '@tarojs/components';
import './index.scss'
import { Cell } from '@antmjs/vantui';
import { formatDate, formatNumber, getNormarlReplace } from '@/utils/fomatter';
import { findNameByFieldNameAndDictItemValue } from '@/services/api/common';
import { stringifyUrl } from 'query-string';

interface FundDetailOverViewProps {
    className?:string;
    detailData:any
}

class FundDetailOverView extends Component<FundDetailOverViewProps,any> {

   config = {
       navigationBarTitleText: ''
  }

  state={}

  componentWillMount () {}
  componentDidMount () {} 
  componentWillReceiveProps (nextProps,nextContext) {} 
  componentWillUnmount () {} 

  renderRightIcon(value){
    const {detailData} = this.props
     return <View onClick={(e) => this.gotoFundManagerNo()}>
        <Text className={`${detailData['fundManagerNo'] && detailData['fundManagerNo'].length > 0 ? 'fund-manager-blue' : ''}`}>{value}</Text>
     </View>
  }

  gotoFundManagerNo(){
    const {detailData} = this.props
    if(detailData['fundManagerNo'] && detailData['fundManagerNo'].length > 0){
      Taro.navigateTo({ url: stringifyUrl({ url: '/preIpoFund/manager/index', query: { 'fundManagerNo': detailData['fundManagerNo'] } }, { encode: false }) })
    }
  }
  
  render() {
    const {className,detailData} = this.props
    return (
      <View className={`fund-detail-over-view ${className}`}>
          <Cell title='产品名称' value={getNormarlReplace(detailData['fundName'],'-')} border={false} />
            <Cell title='产品编码' value={getNormarlReplace(detailData['fundCode'],'-')} border={false} />
            <Cell title='产品类型' value={getNormarlReplace(findNameByFieldNameAndDictItemValue('fund_type',detailData['fundType']),'-')} border={false} />
            <Cell title='基金托管人' value={getNormarlReplace(detailData['fundCustodian'],'-')} border={false} />
            <Cell title='基金管理人' renderRightIcon={this.renderRightIcon(getNormarlReplace(detailData['fundManager'],'-'))}   border={false} />

            <Cell title='策略类型' value={getNormarlReplace(findNameByFieldNameAndDictItemValue('policy_type',detailData['policyType']),'-')} border={false} />

            <Cell title='风险等级' value={getNormarlReplace(findNameByFieldNameAndDictItemValue('risk_level',detailData['riskLevel']),'-')} border={false} />
            <Cell title='币种' value={getNormarlReplace(detailData['currency'],'-')} border={false} />

            <Cell title='最小投资金额' value={(Number(detailData?.subscribeThreshold)  > 0 ? formatNumber(detailData.subscribeThreshold / 10000, 2)  + '万元' : '-')} border={false} />
            <Cell title='最小追加金额' value={(Number(detailData?.minSuperAmt)  > 0 ? formatNumber(detailData.minSuperAmt / 10000, 2) + '万元' : '-') } border={false} />

            <Cell title='成立时间' value={getNormarlReplace(formatDate(detailData['fundFoundDateTs'],'yyyy-MM-DD'),'-')} border={false} />

            <Cell title='结束日期' value={getNormarlReplace(formatDate(detailData['fundExpireDateTs'],'yyyy-MM-DD'),'-')} border={false} />

            <Cell title='备案编号' value={getNormarlReplace(detailData['beianFundNo'],'-')} border={false} />
      </View> 
    );
  }
}
export default FundDetailOverView;